package reseauclient;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

import reseauserv.AccepterConnexion;
import reseauserv.Reception;
import reseauserv.Serveur;

public class Client {
	
	

	static final int PORT = 11431;
	private String identifiant;
	private Socket socket ;
	private BufferedReader plec;
	private PrintWriter pred;
	
	public Client(String id, String adresse) throws Exception {
     this.identifiant = id;
	 this.socket = new Socket(adresse, PORT);
     this.plec = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     this.pred = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
     Thread t2 = new Thread(new Reception(this.plec));
     t2.run();
      
     }
	
	public Client(Serveur serveur, String id, String adresse){
		this.identifiant = id;
		Thread t = new Thread(new AccepterConnexion(serveur));
		t.run();
	}
	
	
	
	public void finTour() throws IOException{
		pred.println("end");					
	}
	
	public void fermetureSocket() throws IOException {
		pred.println("close");
		}

	public String getIdentifiant() {
		return identifiant;
	}

	public void setIdentifiant(String identifiant) {
		this.identifiant = identifiant;
	}

	public Socket getSocket() {
		return socket;
	}

	public void setSocket(Socket socket) {
		this.socket = socket;
	}

	public BufferedReader getPlec() {
		return plec;
	}

	public void setPlec(BufferedReader plec) {
		this.plec = plec;
	}

	public PrintWriter getPred() {
		return pred;
	}

	public void setPred(PrintWriter pred) {
		this.pred = pred;
	}
	

	
}
